students=[]
while True:
    data=input().split()
    if data[0]=="#":
        break
    sid=data[0]
    name=data[1]
    chinese=int(data[2])
    math=int(data[3])
    english=int(data[4])
    total=chinese+math+english
    students.append((total,int(sid),sid,name))
students.sort()
for s in students:
    print(f"{s[2]}, {s[3]}, {s[0]}")
